var data_zh = ['你知道吗', '六月', '一日', '星期一', '是', '儿童节'];
var data_en = ['do you know', 'June', 'One day', 'Monday', 'Yes', 'Children\'s day'];

var but_if=document.querySelectorAll("#but_if button");
var but_that=document.querySelectorAll("#but_that button");
var but1=document.querySelectorAll("#but1");
var tex1=document.querySelector("#tex1");
var tex2=document.querySelector("#tex2");
var but2=document.querySelectorAll("#but2");

var lang="en";
function  lan(){
    if (lang=='en'){
        lang='zh';
    }else {
        lang='en';
    }
    for (var i=0;i<but_if.length;i++){
        but_if[i].classList.remove('active');
        but_that[i].classList.remove('active');
    }
switch (lang){
    case 'zh':
    but_if[0].classList.remove('active');
    but_if[1].classList.add('active');
    but_that[0].classList.add('active');
    but_that[1].classList.remove('active');
    break;
    case 'en':
        but_if[0].classList.add('active');
        but_if[1].classList.remove('active');
        but_that[0].classList.remove('active');
        but_that[1].classList.add('active');
     break;
    }
}

function res(){
    var data;
    var if_text=false;

    for (var i=0;i<=data_zh.length;i++){
        if(tex1.value==data_zh[i]){
            if_text=true;
            data=data_zh;
            tex2.value=data_en[i];

            if (lang=='zh'){
                lan();
            }
        }
    }

    for (var i=0;i<=data_en.length;i++){
        if (tex1.value==data_en[i]){
            if_text=true;
            data=data_en;
            tex2.value=data_zh[i];

            if (lang=="en"){
                lan();
            }
        }
    }
    if (!if_text){
        tex2.value='';
        alert("无法翻译");
    }
}

